package com.example.smartcity.ui.Adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.smartcity.R;
import com.example.smartcity.ui.Bean.topicFunctionBean;

import java.util.ArrayList;

public class RecycleViewAdapter extends RecyclerView.Adapter<RecycleViewAdapter.MyViewHolder> {


    private int resource;
    private boolean flag = true;

    ArrayList<topicFunctionBean> list = new ArrayList<>();
    public RecycleViewAdapter(ArrayList<topicFunctionBean> list,int Resource){
        this.list = list;
        this.resource = Resource;
    }


    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(resource,parent,false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
            holder.textView.setText(list.get(position).getTitle());
            holder.imageView.setImageResource(list.get(position).getIcon());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }



    class MyViewHolder extends RecyclerView.ViewHolder{

        ImageView imageView;
        TextView textView;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
                imageView = itemView.findViewById(R.id.IV_topicFunctionIcon);
                textView = itemView.findViewById(R.id.TV_topicFunctionTitle);
                itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (setOnItemClickListener!=null){
                            setOnItemClickListener.OnItemClickLister(getAdapterPosition());
                        }
                    }
                });
        }
    }


    public OnRecyclerViewItemClickListener setOnItemClickListener;

    public void setOnItemClickListener(OnRecyclerViewItemClickListener onRecyclerViewItemClickListener) {
        this.setOnItemClickListener = onRecyclerViewItemClickListener;
    }

    public interface OnRecyclerViewItemClickListener{
        void OnItemClickLister(int position);
    }
}
